]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
main: Pass script on CLI instead of via environment
authorFlorian Müllner <fmuellner@gnome.org>
Tue, 13 Jun 2023 01:53:32 +0000 (03:53 +0200)
committerFlorian Müllner <fmuellner@gnome.org>
Fri, 7 Jul 2023 17:43:28 +0000 (19:43 +0200)
Environment variables aren't the best option to pass parameters
to a process (wouldn't it be "fun" if SHELL_PERF_MODULE appeared
in a regular user session?).

Instead, use a (hidden) --automation-script command line flag to
specify a script file that should be used to drive an automated
session.

As a side effect, the script no longer has to be relative to the
main module itself, so it will be possible to run scripts that
aren't bundled with the shell sources.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2812>

js/ui/main.js
src/gnome-shell-perf-tool.in
src/main.c
src/shell-global.c
tests/meson.build

index e277224b9901b5155ddf162b5b08485a3d898901..ece09131989505d0856d816140b710c21228d201 100644 (file)
@@ -326,9 +326,9 @@ async function _initializeUI() {
     }
 
     let perfModule;
-    const perfModuleName = GLib.getenv('SHELL_PERF_MODULE');
-    if (perfModuleName) {
-        perfModule = await import(`../perf/${perfModuleName}.js`);
+    const {automationScript} = global;
+    if (automationScript) {
+        perfModule = await import(automationScript.get_uri());
         if (perfModule.init)
             perfModule.init();
     }
index 6f5273c505c0b42e0859f576662eba3da01c49ee..3911df8ffc6b8a222fc121fdcba9e6ca9a4e47d9 100755 (executable)
@@ -27,7 +27,6 @@ def show_version(option, opt_str, value, parser):
 def start_shell(wrap=None, perf_output=None):
     # Set up environment
     env = dict(os.environ)
-    env['SHELL_PERF_MODULE'] = options.perf
 
     filters = ['Gnome-shell-perf-helper'] + options.extra_filter
     env['MUTTER_WM_CLASS_FILTER'] = ','.join(filters)
@@ -45,6 +44,9 @@ def start_shell(wrap=None, perf_output=None):
         args += wrap.split(' ')
     args.append(os.path.join(self_dir, 'gnome-shell'))
 
+    args.append('--automation-script')
+    args.append(options.script)
+
     args.append('--force-animations')
 
     if options.replace:
@@ -173,7 +175,7 @@ def gnome_hwtest_log(*args):
     subprocess.check_call(command)
 
 def run_performance_test(wrap=None):
-    iters = options.perf_iters
+    iters = options.test_iters
     if options.perf_warmup:
         iters += 1
 
@@ -286,10 +288,10 @@ def run_performance_test(wrap=None):
 # Main program
 
 parser = argparse.ArgumentParser()
-parser.add_argument("--perf",
-                    help="Specify the name of a performance module to run")
-parser.add_argument("--perf-iters", type=int, metavar="ITERS",
-                    help="Numbers of iterations of performance module to run",
+parser.add_argument("--script",
+                    help="Specify the path to the automation script to run")
+parser.add_argument("--test-iters", type=int, metavar="ITERS",
+                    help="Numbers of iterations of the test to run",
                     default=1)
 parser.add_argument("--perf-warmup", action="store_true",
                     help="Run a dry run before performance tests")
@@ -321,16 +323,16 @@ parser.add_argument("--hotplug", action="store_true",
 
 options = parser.parse_args()
 
-if options.perf == None:
+if options.script == None:
     if options.hwtest:
-        options.perf = 'hwtest'
+        options.script = 'resource:///org/gnome/shell/perf/hwtest.js'
     else:
-        options.perf = 'core'
+        options.script = 'resource:///org/gnome/shell/perf/core.js'
 
 if options.extra_filter is None:
     options.extra_filter = []
 
-if options.perf == 'hwtest':
+if options.script == 'hwtest':
     options.extra_filter.append('Gedit')
 
 normal_exit = run_performance_test(wrap=options.wrap)
index 1bfa05e4bd6efe109e59a7570a74a1110ec91cb3..bbf84599913f4fa9624a89cffd55a6e669c412f2 100644 (file)
@@ -39,6 +39,7 @@ static gboolean is_gdm_mode = FALSE;
 static char *session_mode = NULL;
 static int caught_signal = 0;
 static gboolean force_animations = FALSE;
+static char *script_path = NULL;
 
 #define DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER 1
 #define DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER 4
@@ -532,6 +533,12 @@ GOptionEntry gnome_shell_options[] = {
     N_("Force animations to be enabled"),
     NULL
   },
+  {
+    "automation-script", 0, G_OPTION_FLAG_HIDDEN, G_OPTION_ARG_FILENAME,
+    &script_path,
+    N_(""),
+    NULL
+  },
   { NULL }
 };
 
@@ -582,6 +589,8 @@ int
 main (int argc, char **argv)
 {
   g_autoptr (MetaContext) context = NULL;
+  g_autoptr (GFile) automation_script = NULL;
+  g_autofree char *cwd = NULL;
   GError *error = NULL;
   int ecode = EXIT_SUCCESS;
 
@@ -606,6 +615,7 @@ main (int argc, char **argv)
   meta_context_set_gnome_wm_keybindings (context, GNOME_WM_KEYBINDINGS);
 
   init_signal_handlers (context);
+  cwd = g_get_current_dir ();
   change_to_home_directory ();
 
   if (session_mode == NULL)
@@ -628,12 +638,16 @@ main (int argc, char **argv)
       dump_gjs_stack_on_signal (SIGSEGV);
     }
 
+  if (script_path)
+    automation_script = g_file_new_for_commandline_arg_and_cwd (script_path, cwd);
+
   /* Initialize the Shell global, including GjsContext
    * GjsContext will iterate the default main loop to
    * resolve internal modules.
    */
   _shell_global_init ("session-mode", session_mode,
                       "force-animations", force_animations,
+                      "automation-script", automation_script,
                       NULL);
 
   /* Setup Meta _after_ the Shell global to avoid GjsContext
index aae9469abf589c9c3d03884880df2a82d42a9e0b..761ba331c4589e39c62ebcb48a4abeb08e4f16a8 100644 (file)
@@ -73,6 +73,7 @@ struct _ShellGlobal {
   char *userdatadir;
   GFile *userdatadir_path;
   GFile *runtime_state_path;
+  GFile *automation_script;
 
   ShellWindowTracker *window_tracker;
   ShellAppSystem *app_system;
@@ -120,6 +121,7 @@ enum {
   PROP_FRAME_FINISH_TIMESTAMP,
   PROP_SWITCHEROO_CONTROL,
   PROP_FORCE_ANIMATIONS,
+  PROP_AUTOMATION_SCRIPT,
 
   N_PROPS
 };
@@ -249,6 +251,9 @@ shell_global_set_property(GObject         *object,
     case PROP_FORCE_ANIMATIONS:
       global->force_animations = g_value_get_boolean (value);
       break;
+    case PROP_AUTOMATION_SCRIPT:
+      g_set_object (&global->automation_script, g_value_get_object (value));
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -338,6 +343,9 @@ shell_global_get_property(GObject         *object,
     case PROP_FORCE_ANIMATIONS:
       g_value_set_boolean (value, global->force_animations);
       break;
+    case PROP_AUTOMATION_SCRIPT:
+      g_value_set_object (value, global->automation_script);
+      break;
     default:
       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
       break;
@@ -688,6 +696,13 @@ shell_global_class_init (ShellGlobalClass *klass)
                           FALSE,
                           G_PARAM_READWRITE  | G_PARAM_CONSTRUCT| G_PARAM_STATIC_STRINGS);
 
+  props[PROP_AUTOMATION_SCRIPT] =
+    g_param_spec_object ("automation-script",
+                         "automation-script",
+                         "Automation script to run after startup",
+                         G_TYPE_FILE,
+                         G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY | G_PARAM_STATIC_STRINGS);
+
   g_object_class_install_properties (gobject_class, N_PROPS, props);
 }
 
index 85339dd141acd1b1b48a920bc5769bd1db292551..5d52d80fd8f994d914851abcc23e08964f6707ca 100644 (file)
@@ -71,7 +71,7 @@ foreach perf_test : perf_tests
     args: [
       perf_tool,
       '--headless',
-      '--perf=@0@'.format(test_name),
+      '--script=@0@/js/perf/@1@.js'.format(meson.project_source_root(), test_name),
       options,
     ],
     is_parallel: false,